import { RosterInterface } from '@/api/interface/personnel/roster/roster';
import { BasicForm } from '@/components/ProForm/interface/index';
import { PublicInterface } from '@/interface/public';
export function useLeaveForm(proTableBox: PublicInterface.ProTableValue) {
  let leaveForm = reactive<BasicForm<RosterInterface.ReqRosterLeave>>({
    form: {
      id: null,
      leaveDate: '',
      leaveType: ''
    },
    title: '',
    visible: false,
    transitionArr: [
      {
        oldField: 'leaveType',
        newField: 'leaveType'
      }
    ],
    options: [
      {
        type: 'input',
        label: 'ID',
        prop: 'id',
        hide: true
      },
      {
        type: 'date-picker',
        label: '离职日期',
        prop: 'leaveDate',
        hide: false,
        attrs: {
          disabled: false,
          type: 'date',
          valueFormat: BasicKey.DATE_FORMAT.YYYY_MM_DD
        },
        rules: [
          {
            required: true,
            message: '离职日期',
            trigger: 'change'
          }
        ]
      },
      {
        type: 'select',
        label: '离职类型',
        prop: 'leaveType',
        hide: false,
        children: [],
        attrs: {
          disabled: false
        },
        rules: [
          {
            required: true,
            message: '离职类型',
            trigger: 'blur'
          }
        ]
      }
    ]
  });

  /**
   * @description: 保存表单数据
   * @param {OperatorInfo} form
   * @return {*}
   */
  const saveLeaveForm = async (form: any) => {
    await rosterLeave(form);
    leaveForm.visible = false;
    elMessage();
    proTableBox.value?.getTableList();
  };

  return { leaveForm, saveLeaveForm };
}
